# -*- coding:utf-8 -*-
#作者：琴弦上的宇宙
#时间：2021年10月22日

import os
from common import *
from openCv import *

class scStoneStart(myScene):
    def __init__(self,bValid):
        self.bValid=bValid
        self.name='scStoneStart'
        self.path='resource/base/scStoneStart'
        self.tagPng=[myPng(self.path,png) for png in os.listdir(self.path) if png.startswith('tag')]
        self.funcPng=[myPng(self.path,png) for png in os.listdir(self.path) if png.startswith('func')]

    def enable(self):
        self.bValid=True

    def dis(self):
        self.bValid=False

    def isOwn(self,background):
        if self.bValid:
            tagList={}
            for tag in self.tagPng:
                bFind,x,y,w,h=bFindInBackground(background,tag,0.80)
                if bFind:
                    tagList[tag.name]=(x,y,w,h)
            if ('tagBattle' in tagList):
                return True
            else:
                return False
        else:
            return False

    def proc(self,background):

        #循环
        bg=background
        while True:

            #寻找开始游戏
            for func in self.funcPng:
                if (func.name=='funcStart'):
                    bFind,x,y,w,h=bFindInBackground(bg,func,0.80)
                    if bFind:
                        moveAndClick(x+w/2,y+h/2,10)
                        return True

            #寻找炉石
            for func in self.funcPng:
                if (func.name=='funcGame'):
                    bFind,x,y,w,h=bFindInBackground(bg,func,0.80)
                    if bFind:
                        moveAndClick(x+w/2,y+h/2)
                        break

            #重新截图判断
            bg=SaveScreen()
            if not self.isOwn(bg):
                return False
